<template>
    <div class="page add-member">        
        <div class="weui-cells weui-cells_radio select-role">
            <label class="weui-cell weui-check__label" :for="'x'+type.station_id" v-for="(index, type) in types" @click="setType(type.station_id,type.station_name)">
                <div class="weui-cell__bd">
                    <h2>{{type.station_name}}</h2>
                </div>
                <div class="weui-cell__ft">
                    <input type="radio" class="weui-check" name="radio1" :id="'x'+type.station_id" v-bind:checked="selectedPostId == type.station_id">
                    <span class="weui-icon-checked"></span>
                </div>
            </label>
        </div>
    </div>   
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    import $ from 'zepto'
    import widget from 'gapi/widget.js'
    import cache from 'gapi/cache'
    import * as util from 'js/util.js'
    import userCenterApi from 'clientApi/userCenterApi'
    import clientInfo from 'gapi/clientInfo'
    import commonPage from 'clientApi/commonPage.js'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    /**
     *  组件实例对象
     */
    export default {
        components: {

        },
        data: function(){
            return{
                types: [],
                userId: '',
                selectedTypeId : '',
                roleType: {
                    roleid: '',
                    rolename: ''
                },
                isClick: false,
                selectedPostId : '',
                projectId: '',
                teamId: '',
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
              this.projectId = util.getUrddataString('pId')
              this.teamId = util.getUrddataString('tId')
              //获取岗位列表
              this.getPostList()
            },
            getPostList (){
              util.ajax({
                    url:'/project/station/get',
                    type:'GET',
                    data:{
                      team_id: this.teamId,
                      project_id: this.projectId,
                    },
                    timeout:10000,
                    success:(obj) => {
                        if(obj.errno == 0){
                            this.types = obj.data
                        }
                    },
                    error: (xhr, status) => {
                        // error
                        console.log(xhr)
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            //选择角色
            setType (typeId,typeName){
                if(this.isClick){
                    return
                }
                this.isClick = true
                let memberList = {
                    id: typeId,
                    name: typeName 
                }
                cache.getMemoryCache('webViewID',function(data){
                    if(data){
                        setTimeout(() =>{ 
                            commonPage.goBack(1,{'key':'selectPost','value':memberList},data.webViewID)},200)
                    }
                })
                
            }
        },
        created(){

            this.init();

        },
        ready(){
            cache.getMemoryCache('projectTypeId', (data) => {
                    if(data){
                        this.selectedTypeId = data
                    }
            })
            cache.getMemoryCache('postMessage', (data) => {
                    if(data && data.station_id){
                        this.selectedPostId = data.station_id
                    }
            })

        }

    }


</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/project.css"></style>
<style>
    .weui-cells_radio .weui-check:checked + .weui-icon-checked:before {
      display: block;
      content: "";
      width: 18px;
      height: 18px;
      background-image: url(../../static/imgs/single_selected.png);
      background-size: 18px 18px;
      overflow: hidden;
    }
</style>
